{{ define "left" }}
  {{ partial "sidebar.html" . }}
{{ end }}

{{ define "main" }}
  {{ $data := "" }}
  {{ if .Params.datafolder }}
    {{ $data = index (index site.Data .Params.datafolder) .Params.datafile }}
  {{ else }}
    {{ $data = index site.Data .Params.datafile }}
  {{ end }}
  {{ .Scratch.Set "headings" slice }}
  {{ .Scratch.Set "subheadings" slice }}
  {{ partial "breadcrumbs.html" . }}
  <article class="prose max-w-none dark:prose-invert">
    <h1 class="scroll-mt-36">{{ .Title }}</h1>
    <table>
      <tbody>
        {{ with $data.short }}
        <tr>
          <th class="text-left w-32">Description</th>
          <td>{{ . }}</th>
        </tr>
        {{ end }}
        {{ with $data.usage }}
        <tr>
          <th class="text-left w-32">Usage</th>
          <td><code>{{ . }}</code></td>
        </tr>
        {{ end }}
        {{ with $data.aliases }}
        {{ $aliases := strings.Replace . (fmt.Printf "%s, " page.Title) "" }}
        <tr>
          <th class="text-left w-32 flex items-center gap-2">
            <span>Aliases</span>
            {{ partialCached "tooltip.html" "An alias is a short or memorable alternative for a longer command." "cli-alias" }}
          </th>
          <td>
            <div class="flex gap-3">
            {{ range (strings.Split $aliases ", ") }}
              <code>{{ . }}</code>
            {{ end }}
            </div>
          </td>
        </tr>
        {{ end }}
      </tbody>
    </table>
    {{ .Content }}
    {{ if $data.deprecated }}
      <blockquote class="warning">
        <p><strong>This command is deprecated</strong></p>
        <p>
          It may be removed in a future Docker version. For more information,
          see the
          <a href="https://github.com/docker/roadmap/issues/209"
            >Docker roadmap</a
          >
        </p>
      </blockquote>
    {{ end }}
    {{ if or $data.experimental $data.experimentalcli }}
      <blockquote class="important">
        <p><strong>This command is experimental</strong></p>
        <p>
          Experimental features are intended for testing and feedback as their
          functionality or design may change between releases without warning or
          can be removed entirely in a future release.
        </p>
      </blockquote>
    {{ end }}
    {{ with $data.kubernetes }}
      <p>
        {{ partialCached "components/badge.html" (dict "color" "blue" "content" "Kubernetes") "k8s" }}
        This command works with the Kubernetes orchestrator.
      </p>
    {{ end }}
    {{ with $data.swarm }}
      <p>
        {{ partialCached "components/badge.html" (dict "color" "blue" "content" "Swarm") "swarm" }}
        This command works with the Swarm orchestrator.
      </p>
    {{ end }}
    {{ with $data.long }}
      {{ $heading := dict "level" 2 "text" "Description" }}
      {{ partialCached "heading.html" $heading "cli-description" }}
      {{ $subHeadings := (strings.FindRE `(?m:#{3,4} .*)` .) }}
      {{ $.Scratch.Add "headings" $heading }}
      {{ range $subHeadings }}
        {{ $lvl := strings.Count "#" . }}
        {{ $txt := strings.TrimLeft "# " . }}
        {{ $.Scratch.Add "headings" (dict "level" $lvl "text" $txt) }}
      {{ end }}
      {{ . | $.RenderString (dict "display" "block") }}
    {{ end }}
    {{ with $data.options }}
      {{ $opts := where . "hidden" false }}
      {{ with $opts }}
        {{ $heading := dict "level" 2 "text" "Options" }}
        {{ partialCached "heading.html" $heading "cli-options" }}
        {{ $.Scratch.Add "headings" $heading }}
        <table>
          <thead>
            <tr>
              <th>Option</th>
              <th>Default</th>
              <th>Description</th>
            </tr>
          </thead>
          <tbody>
            {{ range . }}
              <tr>
                {{ $short := .shorthand }}
                {{ $long := .option }}
                <td>
                  {{ with .details_url }}
                  <a class="link" href="{{ . }}">
                    <code>{{ with $short }}-{{ . }}, {{end}}--{{ $long }}</code>
                  </a>
                  {{ else }}
                  <code>{{ with $short }}-{{ . }}, {{end}}--{{ $long }}</code>
                  {{ end }}
                </td>
                {{ $skipDefault := `[],map[],false,0,0s,default,'',""` }}
                <td>
                  {{ with .default_value }}
                    {{ cond (in $skipDefault .) "" (printf "<code>%s</code>" . | safeHTML) }}
                  {{ end }}
                </td>
                <td>
                  {{ with .min_api_version }}
                    {{ partialCached "components/badge.html" (dict "color" "blue" "content" (printf "API %s+" .)) "api" . }}
                  {{ end }}
                  {{ with .deprecated }}
                    {{ partialCached "components/badge.html" (dict "color" "red" "content" "Deprecated") "deprecated" }}
                  {{ end }}
                  {{ with .experimental }}
                    {{ partialCached "components/badge.html" (dict "color" "amber" "content" "experimental (daemon)") "exp" }}
                  {{ end }}
                  {{ with .experimentalcli }}
                    {{ partialCached "components/badge.html" (dict "color" "amber" "content" "experimental (CLI)") "exp-cli" }}
                  {{ end }}
                  {{ with .kubernetes }}
                    {{ partialCached "components/badge.html" (dict "color" "blue" "content" "Kubernetes") "k8s" }}
                  {{ end }}
                  {{ with .swarm }}
                    {{ partialCached "components/badge.html" (dict "color" "blue" "content" "Swarm") "swarm" }}
                  {{ end }}
                  {{ if .description }}
                    {{/* replace newlines in long desc with break tags */}}
                    {{ markdownify (strings.Replace .description "\n" "<br>") }}
                  {{ end }}
                </td>
              </tr>
            {{ end }}
          </tbody>
        </table>
      {{ end }}
    {{ end }}
    {{ with $data.examples }}
      {{ $heading := dict "level" 2 "text" "Examples" }}
      {{ partialCached "heading.html" $heading "cli-examples" }}
      {{ $subHeadings := (strings.FindRE `(?m:#{3,4} .*)` .) }}
      {{ $.Scratch.Add "headings" $heading }}
      {{ range $subHeadings }}
        {{ $lvl := strings.Count "#" . }}
        {{ $txt := strings.TrimLeft "# " . }}
        {{ $.Scratch.Add "headings" (dict "level" $lvl "text" $txt) }}
      {{ end }}
      {{ $.RenderString (dict "display" "block") . }}
    {{ end }}
    {{ if eq .Kind "section" }}
      {{ $heading := dict "level" 2 "text" "Subcommands" }}
      {{ partialCached "heading.html" $heading "cli-subcommands" }}
      {{ $.Scratch.Add "headings" $heading }}
      <table>
        <thead>
          <tr>
            <th class="text-left">Command</th>
            <th class="text-left">Description</th>
          </tr>
        </thead>
        <tbody>
          {{ range .Pages }}
            <tr>
              <td class="text-left"><a class="link" href="{{ .Permalink }}"><code>{{ .Title }}</code></a></th>
              {{ $data := index (index site.Data .Params.datafolder) .Params.datafile }}
              <td class="text-left">{{ $data.short }}</th>
            </tr>
          {{ end }}
        </tbody>
      </table>
    {{ end }}
  </article>
{{ end }}

{{ define "right" }}
  {{ partial "cli-aside.html" . }}
{{ end }}
